<!DOCTYPE html>
<html lang="en">
<head>
    <link rel="stylesheet" href="/static/pear/component/pear/css/pear.css" />
    <style>
        .hd-form-upload {
            width: 80px;
            height: 80px;
            display: inline-block;
            cursor: pointer;
        }

        .hd-form-upload input {
            display: none;
        }

        .hd-form-upload span {
            width: 80px;
            height: 80px;
            line-height: 80px;
            text-align: center;
            float: left;
            overflow: hidden;
            background-color: #ddd;
        }

        .hd-form-upload span img {
            width: 100%;
            display: inline;
            vertical-align: middle;
        }

        .hd-form-upload span i {
            width: 80px;
            height: 80px;
            float: left;
            position: relative;
        }

        .hd-form-upload  span i:before {
            content: "";
            border-top: 2px solid #bbb;
            position: absolute;
            top: 39px;
            left: 20px;
            right: 20px;
        }

        .hd-form-upload  span i:after {
            content: "";
            border-right: 2px solid #bbb;
            position: absolute;
            top: 20px;
            left: 39px;
            bottom: 20px;
        }
    </style>
</head>
<body>
<form class="layui-form">
    <div class="mainBox  layui-card-body" style="padding: 0 0;">
        <div class="main-container">
            <div class="layui-form-item">
                <label class="layui-form-label">课程标题*</label>
                <div class="layui-input-block">
                    <input type="text" name="seminar" value="{$inf.seminar}" lay-verify="required" placeholder="请输入课程标题" autocomplete="off" class="layui-input">
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">Seminar(en)*</label>
                <div class="layui-input-block">
                    <input type="text" name="e_seminar" value="{$inf.e_seminar}" lay-verify="required" placeholder="请输入Seminar(en)" autocomplete="off" class="layui-input">
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">封面图片*</label>
                <div class="layui-input-block">
                    <label class="hd-form-upload" id="image">
                        <span id="thumb-img-thumb">
                            {empty name="inf.img"}
                                <i></i>
                            {else /}
                                <img src="{$inf.img}" />
                            {/empty}
                        </span>
                    </label>
                    <input type="hidden" id="img_thumb" name="img" value="{$inf.img}"/>
                </div>
            </div>
            <div class="layui-input-block">
                <div class="layui-form-mid layui-word-aux">封面图尺寸为16:9</div>
            </div>

<!--            <div class="layui-form-item">-->
<!--                <label class="layui-form-label">封面视频</label>-->
<!--                <div class="layui-input-block" style="display: flex;">-->
<!--                    <div class="layui-upload-drag" id="coursevideo">-->
<!--                        <i class="layui-icon"></i>-->
<!--                        <p>点击上传，或将文件拖拽到此处。封面视频尺寸为16:9</p>-->
<!--                    </div>-->
<!--                    <input type="hidden" name="video" id="videopath" value="{$inf.video}">-->
<!--                    {empty name="inf.video"}-->
<!--                    <div id="img1" style="position: relative; display: none;">-->
<!--                        <div style="width:250px;height:140px;float:left;">-->
<!--                            <video id="video" src="" controls="controls" autoplay height="140" width="250">您的浏览器不支持。</video>-->
<!--                        </div>-->
<!--                        <button id="del_video" type="button" class="layui-btn layui-btn-xs layui-btn-primary">-->
<!--                            <i class="layui-icon">&#xe640;</i>-->
<!--                        </button>-->
<!--                    </div>-->
<!--                    {else/}-->
<!--                    <div id="img1" style="position: relative;">-->
<!--                        <div style="width:250px;height:140px;float:left;">-->
<!--                            <video id="video" src="{$inf.video}" controls="controls" autoplay height="140" width="250">您的浏览器不支持。</video>-->
<!--                        </div>-->
<!--                        <button id="del_video" type="button" class="layui-btn layui-btn-xs layui-btn-primary">-->
<!--                            <i class="layui-icon">&#xe640;</i>-->
<!--                        </button>-->
<!--                    </div>-->
<!--                    {/empty}-->
<!--                </div>-->
<!--            </div>-->

            <div class="layui-form-item">
                <label class="layui-form-label">Courseid*</label>
                <div class="layui-input-block">
                    <input type="text" name="courseid" value="{$inf.courseid}" lay-verify="required" placeholder="请输入Courseid" autocomplete="off" class="layui-input">
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">课程属性</label>
                <div class="layui-input-block">
                    <select name="type" lay-verify="required">
                        <option value="">课程属性</option>
                        {volist name="type" id="vo" key="k"}
                        <option value="{$k}" {eq name="inf.type" value="$k"}selected{/eq} disabled>{$vo}</option>
                        {/volist}
                    </select>
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">课程分类</label>
                <div class="layui-input-block">
                    <select name="seminar_topic" lay-verify="required">
                        <option value="">课程分类</option>
                        {volist name="seminar_topic" id="vo"}
                        <option value="{$vo.id}" {eq name="inf.seminar_topic" value="$vo.id"}selected{/eq}>{$vo.e_title}</option>
                        {/volist}
                    </select>
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">语言等级</label>
                <div class="layui-input-block">
                    <select name="english" lay-verify="required">
                        <option value="">课程语言</option>
                        {volist name="english" id="vo"}
                        <option value="{$vo.id}" {eq name="inf.english" value="$vo.id"}selected{/eq}>{$vo.name}</option>
                        {/volist}
                    </select>
                </div>
            </div>

            <div class="layui-form-item layui-form-text">
                <label class="layui-form-label">目标学员描述*</label>
                <div class="layui-input-block">
                    <textarea name="target_audience" placeholder="请填写目标学员的描述信息" class="layui-textarea">{$inf.target_audience}</textarea>
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">先修课程</label>
                <div class="layui-input-block">
                    <select name="prerequisite">
                        <option value="">请选择先修课程</option>
                        {volist name="data" id="vo"}
                        <option value="{$vo.courseid}" {eq name="inf.prerequisite" value="$vo.courseid"}selected{/eq}>{$vo.e_seminar}</option>
                        {/volist}
                    </select>
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">相关课程</label>
                <div class="layui-input-block">
                    <select name="related" xm-select="select4" xm-select-skin="default">
                        {notempty name="inf.related"}
                            {volist name="inf.related" id="vo1"}
                            <option value="{$vo1.courseid}" selected="selected">{$vo1.e_seminar}</option>
                            {/volist}
                        {/notempty}
                        {volist name="data" id="vo"}
                        <option value="{$vo.courseid}">{$vo.e_seminar}</option>
                        {/volist}
                    </select>
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">课程等级</label>
                <div class="layui-input-block">
                    <select name="level" lay-verify="required">
                        <option value="">课程等级</option>
                        {volist name="level" id="vo"}
                        <option value="{$vo.id}" {eq name="inf.level" value="$vo.id"}selected{/eq}>{$vo.name}</option>
                        {/volist}
                    </select>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">课程天数*</label>
                <div class="layui-input-block">
                    <input type="number" name="days" value="{$inf.days}" lay-verify="required" placeholder="请输入课程天数" autocomplete="off" class="layui-input">
                </div>
            </div>

            <div class="layui-form-item layui-form-text">
                <label class="layui-form-label">课程详情*</label>
                <div class="layui-input-block">
                    <textarea name="description" id="description" class="layui-textarea">{$inf.description}</textarea>
                </div>
            </div>

            <input type="hidden" name="id" value="{$inf.id}">
            {:token_field()}
        </div>
    </div>


    <div class="bottom">
        <div class="button-container">
            <button type="submit" class="pear-btn pear-btn-primary pear-btn-sm" lay-submit=""
                    lay-filter="user-save">
                <i class="layui-icon layui-icon-ok"></i>
                提交
            </button>
            <button type="reset" class="pear-btn pear-btn-sm">
                <i class="layui-icon layui-icon-refresh"></i>
                重置
            </button>
        </div>
    </div>
</form>
{include file="_Fragment/javascript" /}
<script>
    layui.use(['form', 'jquery', 'upload', 'element', 'croppers', 'select', 'tinymce'], function() {
        let form = layui.form;
        let upload = layui.upload;
        let select = layui.select;
        let tinymce = layui.tinymce;
        let $ = layui.jquery;

        var description = tinymce.render({
            elem: "#description",
            height: 400,
            images_upload_url: "{:url('Pub/blob')}",
            form: {name:'file'}
        });

        select.render();

        //图片上传
        upload.render({
            elem: '#image'
            ,url: "{:url('Pub/blob')}"
            ,accept:'images'
            ,acceptMime: 'image/*'
            ,exts:'jpeg|jpg|png'
            ,done: function(res) {
                $("#thumb-img-thumb").html('<img src="'+ res.data + '" />');
                $("#img_thumb").val(res.data);
            }
        });

        // //视频上传
        // upload.render({
        //     elem: '#coursevideo'
        //     ,url: "{:url('Pub/blob')}"
        //     ,accept:'video'
        //     ,acceptMime: 'video/mp4'
        //     ,field:'file'
        //     ,size:1024*1024*100
        //     ,exts:'mp4'
        //     ,done: function(res){
        //         if(res.code == 200){
        //             $('#videopath').val(res.data);
        //             $('#img1').css('display','block');
        //             $('#video').attr('src',res.data);
        //         } else {
        //             layer.msg(res.msg);
        //         }
        //     }
        // });
        //
        // $(document).on('click','#del_video',function(){
        //     $('#videopath').val('');
        //     $('#img1').css('display','none');
        // });

        form.on('submit(user-save)', function(data) {
            let loading = layer.load();
            var content = description.getContent();
            data.field.description = '';
            data.field.description += content;
            $.ajax({
                url: '/Course/modify',
                data: JSON.stringify(data.field),
                dataType: 'json',
                contentType: 'application/json',
                type: 'post',
                success: function(result) {
                    layer.close(loading);
                    if (result.status == 0) {
                        layer.msg(result.msg, {
                            icon: 1,
                            time: 1000
                        }, function() {
                            parent.layer.close(parent.layer.getFrameIndex(window
                                .name)); //关闭当前页
                            parent.layui.table.reload("user-table");
                        });
                    } else {
                        layer.msg(result.msg, {
                            icon: 2,
                            time: 1000
                        });
                    }
                }
            })
            return false;
        });
    })
</script>
<script>
</script>
</body>
</html>